package com.wits.qso.dao.impl;

import java.util.Date;

import javax.persistence.Query;

import org.springframework.stereotype.Component;

import com.wits.platform.dao.impl.BaseDaoImpl;
import com.wits.qso.dao.custom.YearDaoCustom;
import com.wits.qso.entity.Year;

@Component
public class YearDaoImpl extends BaseDaoImpl<Year, String> implements YearDaoCustom
{

	public Year findNow(Date now) {
		Query query = em.createQuery( "FROM Year o WHERE o.dateF <= :now AND o.dateT >= :now" );
		query.setParameter( "now", now );

		return (Year) query.getSingleResult();
	}

	public Year findEnabled() {
		Year result = null;
		try {
			result = (Year) em.createQuery( "FROM Year o WHERE o.enabled = '1'" ).getSingleResult();
		} catch (Throwable cause) {
		}

		return result;
	}
	
	public Year findByTitle(String title) {
		Year result = null;
		try {
			Query query = em.createQuery( "FROM Year o WHERE o.title = :title" );
			query.setParameter( "title", title );
			result = (Year) query.getSingleResult();
		} catch (Throwable cause) {
		}

		return result;
	}
}
